package com.epichust.bootumpp.controller;

import com.epichust.bootumpp.model.bo.ReturnBO;
import com.epichust.bootumpp.model.bo.Umpp5TaskOrderBO;
import com.epichust.bootumpp.model.entity.Mbb5OrderBom;
import com.epichust.bootumpp.service.IMbb5OrderBomService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ：longyang
 * @date ：Created in 2021/1/25 14:51
 * @description：订单bom控制层
 */
@RestController
@RequestMapping("api/orderBom")
public class Mbb5OrderBomController {

    @Autowired
    private IMbb5OrderBomService iMbb5OrderBomService;

    @RequestMapping(value = "/getAll", method = {RequestMethod.POST})
    public String getAllMbb5OrderBom(@RequestBody Map<String,Object> map) throws Exception{
        try{
            // 新建返回对象
            Gson gson = new GsonBuilder().serializeNulls().create();
            List<Mbb5OrderBom> list= iMbb5OrderBomService.getAllMbb5OrderBom(map);
            ReturnBO bo = new ReturnBO();
            bo.setState(0);
            bo.setObject(list);
            return gson.toJson(bo);
        }catch(Exception e){
            e.printStackTrace();
            Gson gson = new GsonBuilder().serializeNulls().create();
            ReturnBO bo = new ReturnBO();
            bo.setState(1);
            bo.setObject("查询失败："+e.getMessage());
            return gson.toJson(bo);
        }
    }

    /**
     * 新增订单bom信息
     * @param mbb5OrderBom
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/insert", method = {RequestMethod.POST})
    public String insertAllMbb5OrderBom(@RequestBody Mbb5OrderBom mbb5OrderBom) throws Exception{
        try{
            // 新建返回对象
            Gson gson = new GsonBuilder().serializeNulls().create();
            iMbb5OrderBomService.insertMbb5OrderBom(mbb5OrderBom);
            ReturnBO bo = new ReturnBO();
            bo.setState(0);
            bo.setObject("新增成功");
            return gson.toJson(bo);
        }catch(Exception e){
            e.printStackTrace();
            Gson gson = new GsonBuilder().serializeNulls().create();
            ReturnBO bo = new ReturnBO();
            bo.setState(1);
            bo.setObject("新增失败："+e.getMessage());
            return gson.toJson(bo);
        }
    }

    /**
     * 新增订单bom信息
     * @param mbb5OrderBom
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/update", method = {RequestMethod.POST})
    public String updateAllMbb5OrderBom(@RequestBody Mbb5OrderBom mbb5OrderBom) throws Exception{
        try{
            // 新建返回对象
            Gson gson = new GsonBuilder().serializeNulls().create();
            iMbb5OrderBomService.updateMbb5OrderBom(mbb5OrderBom);
            ReturnBO bo = new ReturnBO();
            bo.setState(0);
            bo.setObject("修改成功");
            return gson.toJson(bo);
        }catch(Exception e){
            e.printStackTrace();
            Gson gson = new GsonBuilder().serializeNulls().create();
            ReturnBO bo = new ReturnBO();
            bo.setState(1);
            bo.setObject("修改失败："+e.getMessage());
            return gson.toJson(bo);
        }
    }
}
